﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

using System.IO;
using System.Data;
using System.Data.SqlClient;

namespace Dal
{
    public static class sys
    {

       
        public static DataSet CheckPassWord( string strUser,string strPwd)
        {
            DataSet ds = null;
            try
            {
           
              
               string sqlCmdtext = "USP_CMN_LOGIN";
               sqlhelper dal = new sqlhelper();
               SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
               dal.AddParameter(sqlcmd, "@USER", DbType.String, strUser);
                  dal.AddParameter(sqlcmd, "@PWD", DbType.String, strPwd);
                  ds=dal.GetDataSet(sqlcmd);
                  return ds;

            }
            catch (Exception ex)
            {
                throw  ex;
            }
    

        }

        
        /// <summary>
        /// 获取basecde
        /// </summary>
        /// <param name="codetype"></param>
        /// <returns></returns>
        public static DataSet GetBasedata()
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_CMN_BASEDATA";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
        #region 部门
        public static DataSet cmn_dept_query(string strxmldata)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_CMN_DEPT_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet cmn_dept_save(string strxmldata, string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_CMN_DEPT";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);
                dal.AddParameter(sqlcmd, "@type", DbType.String, strtype);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
        #region 人员
        public static DataSet Sys_employee_query(string strxmldata)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_SYS_EMPLYEE_QUERY";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);

                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet Sys_employee_save(string strxmldata, string strtype)
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "USP_SYS_EMPLYEE";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.StoredProcedure);
                dal.AddParameter(sqlcmd, "@data", DbType.String, strxmldata);
                dal.AddParameter(sqlcmd, "@type", DbType.String, strtype);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static DataSet Sys_Getdept()
        {
        DataSet ds = null;
            try
            {


                string sqlCmdtext = "select  *  from sys_dept where ActiveFlag='1'";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.Text);               
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataSet Sys_Getroid()
        {
            DataSet ds = null;
            try
            {


                string sqlCmdtext = "select  *  from Sys_role ";
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.Text);
                ds = dal.GetDataSet(sqlcmd);
                return ds;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 密码重置
        /// </summary>
        /// <param name="pwd"></param>
        /// <param name="ryid"></param>
        /// <returns></returns>
        public static object  Sys_Setpwd(string pwd,string ryid)
        {
 
            try
            {


                string sqlCmdtext = string.Format("update Sys_employee set pwd='{0}' where Employee_id='{1}'", pwd, ryid);
                sqlhelper dal = new sqlhelper();
                SqlCommand sqlcmd = dal.GetSqlCommand(sqlCmdtext, CommandType.Text);
               return dal.ExecuteScalar(sqlcmd);
           

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

    }
}
